package com.googlecode.yatspec.parsing;

import com.googlecode.totallylazy.Callable1;
import com.googlecode.totallylazy.Predicate;
import com.googlecode.totallylazy.Sequence;
import com.thoughtworks.qdox.model.Annotation;

import static com.googlecode.totallylazy.Predicates.is;
import static com.googlecode.totallylazy.Predicates.where;

public class AnnotationNameCallable1 implements Callable1<Annotation, String> {
    public static Callable1<? super Annotation, String> name() {
        return new AnnotationNameCallable1();
    }

    public static Predicate<? super Sequence<Annotation>> contains(final Class aClass) {
        return new Predicate<Sequence<Annotation>>() {
            @Override
            public boolean matches(Sequence<Annotation> annotations) {
                return annotations.exists(where(name(), is(aClass.getName())));
            }
        };
    }

    @Override
    public String call(Annotation annotation) throws Exception {
        return annotation.getType().getFullyQualifiedName();
    }
}
